﻿#Include ..\..\_lib\Extend.ahk
#Include ..\..\_lib\Path.ahk
class WorkDir {

  static ins := WorkDir()

  __New() {
    this._dir := A_WorkingDir
  }

  static dir(_ := unset) => IsSet(_) ? WorkDir.ins._dir := _ : WorkDir.ins._dir
  static up() => WorkDir.ins._dir := Path.Dir(WorkDir.ins._dir)
  static enter(p) => WorkDir.ins._dir := Path.Join(WorkDir.ins._dir, p)
  static switch(p) => WorkDir.ins._dir := p

  static getSubDirs() {
    r := []
    loop files WorkDir.ins._dir '/*.*', 'D' {
      if A_LoopFileAttrib ~= "[HRS]"
        continue
      r.Push(A_LoopFileName)
    }
    return r
  }

  static getSubs(mode := 'FD') {
    dirs := [], files := []
    loop files WorkDir.ins._dir '/*.*', mode {
      if A_LoopFileAttrib ~= "[HRS]"
        continue
      if A_LoopFileAttrib ~= '[D]'
        dirs.Push('d ' A_LoopFileName)
      else files.Push('- ' A_LoopFileName)
    }
    return dirs.concat(files)
  }
}


; WorkDir.dir('G:/a/c/e')
; WorkDir.up()
; WorkDir.enter('d')
; MToString WorkDir.dir()
